﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Threading;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

namespace CM.Resources.SDK.Test
{
    class Program
    {

        //文件读取
        public static byte[] readFile(FileInfo File)
        {
            FileStream FStream = new FileStream(File.FullName, FileMode.Open);
            var len = FStream.Length;
            byte[] Data = new byte[len];
            FStream.Read(Data, 0, (int)len);
            FStream.Close();
            return Data;
        }

        public static void Upload(string SiteName, FileInfo file)
        {
            //   string url = "http://assadmin.cm.mc2015.co/HttpHandle/upload";
            string url = "http://localhost:8899/HttpHandle/upload";
            HttpPost p = new HttpPost();
            //单文件
            FileData FData = new FileData();
            FData.SiteName = SiteName;//站点名
            FData.Remark = "None";
            FData.OrgFileName = file.Name;
            FData.Data = readFile(file);
            FData.ClientIP = "192.168.1.130";
            FData.CreateTime = "2015-08-13 15:22:30";

            ReponseBean rb = p.Post(url, FData);//提交数据
            Console.WriteLine(JsonConvert.SerializeObject(rb));
        }
        

        //测试入口
        static void Main(string[] args)
        {
            //DirectoryInfo Dir = new DirectoryInfo(@"D:\Downloads\wallpaper\1920x1080");
            //FileInfo[] Files = Dir.GetFiles();
            //foreach (FileInfo file in Files)
            //{
            //    Upload("chongmi.com", file);
            //}

            Upload("ChongMi", new FileInfo(@"C:\Users\Administrator\Desktop\QQ图片20150818143458.gif"));

            Console.ReadLine();
        }
        
    }
}
